export const createStore = function (reducer, initState) {
  let listeners = [];
  let state = initState;
  function subscribe(handler) {
    listeners.push(handler);
  }

  function getState() {
    return state;
  }
  function dispatch(action) {
    console.log(action);
    
    const currentState = reducer(state, action);
    state = currentState;
    listeners.forEach((handler) => handler());
  }
  return {
    subscribe,
    dispatch,
    getState,
  };
};
